package com.zoe.onelink.test.container.support.ctr.impl;

import com.zoe.onelink.test.container.support.ctr.init.ContainerEnvironmentInitializer;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.utility.DockerImageName;

import java.util.Map;

/**
 * <p>标题: </p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2023</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: ruansheng
 * @date: 2023-01-13
 */
public class NacosContainer extends GenericContainer<NacosContainer> implements ContainerEnvironmentInitializer {

    public NacosContainer(String dockerImageName) {
        super(DockerImageName.parse(dockerImageName));
    }

    @Override
    public void preStart() {
        this.addExposedPort(8848);
        Map<String, String> envMap = Map.of(
                "MODE", "standalone",
                "JVM_XMS", "256m",
                "JVM_XMX", "256m",
                "JVM_XMN", "128m"
        );
        this.withEnv(envMap);
    }

    @Override
    public void afterStarted() {
        String serverAddr = String.format("%s:%s", this.getHost(), this.getMappedPort(8848));
        System.setProperty("spring.cloud.nacos.server-addr", serverAddr);
    }
}
